<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>单例模式</title>
</head>
<body>
	<p>单例模式:1，只会拥有一个实例的对象，2，暴露一个接口提供外接调用</p>
	<p>实用场景：创建一个登录弹窗(页面中只有一个唯一的组件)</p>
	<button>create a single pattern</button>
	<script type="text/javascript">
		//代理模式创建
		let createSingle = function (fn) {
			let instance;
			return function () {
					instance = instance || fn.apply(this, arguments)				
			};
		}
		let singelInstance = function () {
			var div = document.createElement( 'div' );
				div.innerHTML = 'asdasdasd';
				document.body.appendChild( div );
				return div;
		}

		let singleA = createSingle(singelInstance)
		document.querySelector('button').onclick = function () {
			singleA();
		}
			
	</script>
</body>
</html>